<?php
	/**
	 * This is a MetaControl class, providing a QForm or QPanel access to event handlers
	 * and QControls to perform the Create, Edit, and Delete functionality
	 * of the Articlebook class.  This code-generated class
	 * contains all the basic elements to help a QPanel or QForm display an HTML form that can
	 * manipulate a single Articlebook object.
	 *
	 * To take advantage of some (or all) of these control objects, you
	 * must create a new QForm or QPanel which instantiates a ArticlebookMetaControl
	 * class.
	 *
	 * Any and all changes to this file will be overwritten with any subsequent
	 * code re-generation.
	 * 
	 * @package My Application
	 * @subpackage MetaControls
	 * property-read Articlebook $Articlebook the actual Articlebook data class being edited
	 * property QLabel $IdControl
	 * property-read QLabel $IdLabel
	 * property QListBox $ReferenceIDControl
	 * property-read QLabel $ReferenceIDLabel
	 * property QTextBox $AuthorControl
	 * property-read QLabel $AuthorLabel
	 * property QTextBox $EditionControl
	 * property-read QLabel $EditionLabel
	 * property QFloatTextBox $NumberOfPagesControl
	 * property-read QLabel $NumberOfPagesLabel
	 * property QDateTimePicker $PublicationDateControl
	 * property-read QLabel $PublicationDateLabel
	 * property QTextBox $PublisherControl
	 * property-read QLabel $PublisherLabel
	 * property QFloatTextBox $IsbnControl
	 * property-read QLabel $IsbnLabel
	 * property-read string $TitleVerb a verb indicating whether or not this is being edited or created
	 * property-read boolean $EditMode a boolean indicating whether or not this is being edited or created
	 */

	class ArticlebookMetaControlGen extends QBaseClass {
		// General Variables
		protected $objArticlebook;
		protected $objParentObject;
		protected $strTitleVerb;
		protected $blnEditMode;

		// Controls that allow the editing of Articlebook's individual data fields
		protected $lblId;
		protected $lstReferenceIDObject;
		protected $txtAuthor;
		protected $txtEdition;
		protected $txtNumberOfPages;
		protected $calPublicationDate;
		protected $txtPublisher;
		protected $txtIsbn;

		// Controls that allow the viewing of Articlebook's individual data fields
		protected $lblReferenceID;
		protected $lblAuthor;
		protected $lblEdition;
		protected $lblNumberOfPages;
		protected $lblPublicationDate;
		protected $lblPublisher;
		protected $lblIsbn;

		// QListBox Controls (if applicable) to edit Unique ReverseReferences and ManyToMany References

		// QLabel Controls (if applicable) to view Unique ReverseReferences and ManyToMany References


		/**
		 * Main constructor.  Constructor OR static create methods are designed to be called in either
		 * a parent QPanel or the main QForm when wanting to create a
		 * ArticlebookMetaControl to edit a single Articlebook object within the
		 * QPanel or QForm.
		 *
		 * This constructor takes in a single Articlebook object, while any of the static
		 * create methods below can be used to construct based off of individual PK ID(s).
		 *
		 * @param mixed $objParentObject QForm or QPanel which will be using this ArticlebookMetaControl
		 * @param Articlebook $objArticlebook new or existing Articlebook object
		 */
		 public function __construct($objParentObject, Articlebook $objArticlebook) {
			// Setup Parent Object (e.g. QForm or QPanel which will be using this ArticlebookMetaControl)
			$this->objParentObject = $objParentObject;

			// Setup linked Articlebook object
			$this->objArticlebook = $objArticlebook;

			// Figure out if we're Editing or Creating New
			if ($this->objArticlebook->__Restored) {
				$this->strTitleVerb = QApplication::Translate('Edit');
				$this->blnEditMode = true;
			} else {
				$this->strTitleVerb = QApplication::Translate('Create');
				$this->blnEditMode = false;
			}
		 }

		/**
		 * Static Helper Method to Create using PK arguments
		 * You must pass in the PK arguments on an object to load, or leave it blank to create a new one.
		 * If you want to load via QueryString or PathInfo, use the CreateFromQueryString or CreateFromPathInfo
		 * static helper methods.  Finally, specify a CreateType to define whether or not we are only allowed to 
		 * edit, or if we are also allowed to create a new one, etc.
		 * 
		 * @param mixed $objParentObject QForm or QPanel which will be using this ArticlebookMetaControl
		 * @param integer $intId primary key value
		 * @param QMetaControlCreateType $intCreateType rules governing Articlebook object creation - defaults to CreateOrEdit
 		 * @return ArticlebookMetaControl
		 */
		public static function Create($objParentObject, $intId = null, $intCreateType = QMetaControlCreateType::CreateOrEdit) {
			// Attempt to Load from PK Arguments
			if (strlen($intId)) {
				$objArticlebook = Articlebook::Load($intId);

				// Articlebook was found -- return it!
				if ($objArticlebook)
					return new ArticlebookMetaControl($objParentObject, $objArticlebook);

				// If CreateOnRecordNotFound not specified, throw an exception
				else if ($intCreateType != QMetaControlCreateType::CreateOnRecordNotFound)
					throw new QCallerException('Could not find a Articlebook object with PK arguments: ' . $intId);

			// If EditOnly is specified, throw an exception
			} else if ($intCreateType == QMetaControlCreateType::EditOnly)
				throw new QCallerException('No PK arguments specified');

			// If we are here, then we need to create a new record
			return new ArticlebookMetaControl($objParentObject, new Articlebook());
		}

		/**
		 * Static Helper Method to Create using PathInfo arguments
		 *
		 * @param mixed $objParentObject QForm or QPanel which will be using this ArticlebookMetaControl
		 * @param QMetaControlCreateType $intCreateType rules governing Articlebook object creation - defaults to CreateOrEdit
		 * @return ArticlebookMetaControl
		 */
		public static function CreateFromPathInfo($objParentObject, $intCreateType = QMetaControlCreateType::CreateOrEdit) {
			$intId = QApplication::PathInfo(0);
			return ArticlebookMetaControl::Create($objParentObject, $intId, $intCreateType);
		}

		/**
		 * Static Helper Method to Create using QueryString arguments
		 *
		 * @param mixed $objParentObject QForm or QPanel which will be using this ArticlebookMetaControl
		 * @param QMetaControlCreateType $intCreateType rules governing Articlebook object creation - defaults to CreateOrEdit
		 * @return ArticlebookMetaControl
		 */
		public static function CreateFromQueryString($objParentObject, $intCreateType = QMetaControlCreateType::CreateOrEdit) {
			$intId = QApplication::QueryString('intId');
			return ArticlebookMetaControl::Create($objParentObject, $intId, $intCreateType);
		}



		///////////////////////////////////////////////
		// PUBLIC CREATE and REFRESH METHODS
		///////////////////////////////////////////////

		/**
		 * Create and setup QLabel lblId
		 * @param string $strControlId optional ControlId to use
		 * @return QLabel
		 */
		public function lblId_Create($strControlId = null) {
			$this->lblId = new QLabel($this->objParentObject, $strControlId);
			$this->lblId->Name = QApplication::Translate('Id');
			if ($this->blnEditMode)
				$this->lblId->Text = $this->objArticlebook->Id;
			else
				$this->lblId->Text = 'N/A';
			return $this->lblId;
		}

		/**
		 * Create and setup QListBox lstReferenceIDObject
		 * @param string $strControlId optional ControlId to use
		 * @return QListBox
		 */
		public function lstReferenceIDObject_Create($strControlId = null) {
			$this->lstReferenceIDObject = new QListBox($this->objParentObject, $strControlId);
			$this->lstReferenceIDObject->Name = QApplication::Translate('Reference I D Object');
			$this->lstReferenceIDObject->AddItem(QApplication::Translate('- Select One -'), null);
			$objReferenceIDObjectArray = Articlecore::LoadAll();
			if ($objReferenceIDObjectArray) foreach ($objReferenceIDObjectArray as $objReferenceIDObject) {
				$objListItem = new QListItem($objReferenceIDObject->__toString(), $objReferenceIDObject->Id);
				if (($this->objArticlebook->ReferenceIDObject) && ($this->objArticlebook->ReferenceIDObject->Id == $objReferenceIDObject->Id))
					$objListItem->Selected = true;
				$this->lstReferenceIDObject->AddItem($objListItem);
			}
			return $this->lstReferenceIDObject;
		}

		/**
		 * Create and setup QLabel lblReferenceID
		 * @param string $strControlId optional ControlId to use
		 * @return QLabel
		 */
		public function lblReferenceID_Create($strControlId = null) {
			$this->lblReferenceID = new QLabel($this->objParentObject, $strControlId);
			$this->lblReferenceID->Name = QApplication::Translate('Reference I D Object');
			$this->lblReferenceID->Text = ($this->objArticlebook->ReferenceIDObject) ? $this->objArticlebook->ReferenceIDObject->__toString() : null;
			return $this->lblReferenceID;
		}

		/**
		 * Create and setup QTextBox txtAuthor
		 * @param string $strControlId optional ControlId to use
		 * @return QTextBox
		 */
		public function txtAuthor_Create($strControlId = null) {
			$this->txtAuthor = new QTextBox($this->objParentObject, $strControlId);
			$this->txtAuthor->Name = QApplication::Translate('Author');
			$this->txtAuthor->Text = $this->objArticlebook->Author;
			$this->txtAuthor->TextMode = QTextMode::MultiLine;
			return $this->txtAuthor;
		}

		/**
		 * Create and setup QLabel lblAuthor
		 * @param string $strControlId optional ControlId to use
		 * @return QLabel
		 */
		public function lblAuthor_Create($strControlId = null) {
			$this->lblAuthor = new QLabel($this->objParentObject, $strControlId);
			$this->lblAuthor->Name = QApplication::Translate('Author');
			$this->lblAuthor->Text = $this->objArticlebook->Author;
			return $this->lblAuthor;
		}

		/**
		 * Create and setup QTextBox txtEdition
		 * @param string $strControlId optional ControlId to use
		 * @return QTextBox
		 */
		public function txtEdition_Create($strControlId = null) {
			$this->txtEdition = new QTextBox($this->objParentObject, $strControlId);
			$this->txtEdition->Name = QApplication::Translate('Edition');
			$this->txtEdition->Text = $this->objArticlebook->Edition;
			$this->txtEdition->MaxLength = Articlebook::EditionMaxLength;
			return $this->txtEdition;
		}

		/**
		 * Create and setup QLabel lblEdition
		 * @param string $strControlId optional ControlId to use
		 * @return QLabel
		 */
		public function lblEdition_Create($strControlId = null) {
			$this->lblEdition = new QLabel($this->objParentObject, $strControlId);
			$this->lblEdition->Name = QApplication::Translate('Edition');
			$this->lblEdition->Text = $this->objArticlebook->Edition;
			return $this->lblEdition;
		}

		/**
		 * Create and setup QFloatTextBox txtNumberOfPages
		 * @param string $strControlId optional ControlId to use
		 * @return QFloatTextBox
		 */
		public function txtNumberOfPages_Create($strControlId = null) {
			$this->txtNumberOfPages = new QFloatTextBox($this->objParentObject, $strControlId);
			$this->txtNumberOfPages->Name = QApplication::Translate('Number Of Pages');
			$this->txtNumberOfPages->Text = $this->objArticlebook->NumberOfPages;
			return $this->txtNumberOfPages;
		}

		/**
		 * Create and setup QLabel lblNumberOfPages
		 * @param string $strControlId optional ControlId to use
		 * @param string $strFormat optional sprintf format to use
		 * @return QLabel
		 */
		public function lblNumberOfPages_Create($strControlId = null, $strFormat = null) {
			$this->lblNumberOfPages = new QLabel($this->objParentObject, $strControlId);
			$this->lblNumberOfPages->Name = QApplication::Translate('Number Of Pages');
			$this->lblNumberOfPages->Text = $this->objArticlebook->NumberOfPages;
			$this->lblNumberOfPages->Format = $strFormat;
			return $this->lblNumberOfPages;
		}

		/**
		 * Create and setup QDateTimePicker calPublicationDate
		 * @param string $strControlId optional ControlId to use
		 * @return QDateTimePicker
		 */
		public function calPublicationDate_Create($strControlId = null) {
			$this->calPublicationDate = new QDateTimePicker($this->objParentObject, $strControlId);
			$this->calPublicationDate->Name = QApplication::Translate('Publication Date');
			$this->calPublicationDate->DateTime = $this->objArticlebook->PublicationDate;
			$this->calPublicationDate->DateTimePickerType = QDateTimePickerType::Date;
			return $this->calPublicationDate;
		}

		/**
		 * Create and setup QLabel lblPublicationDate
		 * @param string $strControlId optional ControlId to use
		 * @param string $strDateTimeFormat optional DateTimeFormat to use
		 * @return QLabel
		 */
		public function lblPublicationDate_Create($strControlId = null, $strDateTimeFormat = null) {
			$this->lblPublicationDate = new QLabel($this->objParentObject, $strControlId);
			$this->lblPublicationDate->Name = QApplication::Translate('Publication Date');
			$this->strPublicationDateDateTimeFormat = $strDateTimeFormat;
			$this->lblPublicationDate->Text = sprintf($this->objArticlebook->PublicationDate) ? $this->objArticlebook->PublicationDate->__toString($this->strPublicationDateDateTimeFormat) : null;
			return $this->lblPublicationDate;
		}

		protected $strPublicationDateDateTimeFormat;


		/**
		 * Create and setup QTextBox txtPublisher
		 * @param string $strControlId optional ControlId to use
		 * @return QTextBox
		 */
		public function txtPublisher_Create($strControlId = null) {
			$this->txtPublisher = new QTextBox($this->objParentObject, $strControlId);
			$this->txtPublisher->Name = QApplication::Translate('Publisher');
			$this->txtPublisher->Text = $this->objArticlebook->Publisher;
			$this->txtPublisher->MaxLength = Articlebook::PublisherMaxLength;
			return $this->txtPublisher;
		}

		/**
		 * Create and setup QLabel lblPublisher
		 * @param string $strControlId optional ControlId to use
		 * @return QLabel
		 */
		public function lblPublisher_Create($strControlId = null) {
			$this->lblPublisher = new QLabel($this->objParentObject, $strControlId);
			$this->lblPublisher->Name = QApplication::Translate('Publisher');
			$this->lblPublisher->Text = $this->objArticlebook->Publisher;
			return $this->lblPublisher;
		}

		/**
		 * Create and setup QFloatTextBox txtIsbn
		 * @param string $strControlId optional ControlId to use
		 * @return QFloatTextBox
		 */
		public function txtIsbn_Create($strControlId = null) {
			$this->txtIsbn = new QFloatTextBox($this->objParentObject, $strControlId);
			$this->txtIsbn->Name = QApplication::Translate('Isbn');
			$this->txtIsbn->Text = $this->objArticlebook->Isbn;
			return $this->txtIsbn;
		}

		/**
		 * Create and setup QLabel lblIsbn
		 * @param string $strControlId optional ControlId to use
		 * @param string $strFormat optional sprintf format to use
		 * @return QLabel
		 */
		public function lblIsbn_Create($strControlId = null, $strFormat = null) {
			$this->lblIsbn = new QLabel($this->objParentObject, $strControlId);
			$this->lblIsbn->Name = QApplication::Translate('Isbn');
			$this->lblIsbn->Text = $this->objArticlebook->Isbn;
			$this->lblIsbn->Format = $strFormat;
			return $this->lblIsbn;
		}



		/**
		 * Refresh this MetaControl with Data from the local Articlebook object.
		 * @param boolean $blnReload reload Articlebook from the database
		 * @return void
		 */
		public function Refresh($blnReload = false) {
			if ($blnReload)
				$this->objArticlebook->Reload();

			if ($this->lblId) if ($this->blnEditMode) $this->lblId->Text = $this->objArticlebook->Id;

			if ($this->lstReferenceIDObject) {
					$this->lstReferenceIDObject->RemoveAllItems();
				$this->lstReferenceIDObject->AddItem(QApplication::Translate('- Select One -'), null);
				$objReferenceIDObjectArray = Articlecore::LoadAll();
				if ($objReferenceIDObjectArray) foreach ($objReferenceIDObjectArray as $objReferenceIDObject) {
					$objListItem = new QListItem($objReferenceIDObject->__toString(), $objReferenceIDObject->Id);
					if (($this->objArticlebook->ReferenceIDObject) && ($this->objArticlebook->ReferenceIDObject->Id == $objReferenceIDObject->Id))
						$objListItem->Selected = true;
					$this->lstReferenceIDObject->AddItem($objListItem);
				}
			}
			if ($this->lblReferenceID) $this->lblReferenceID->Text = ($this->objArticlebook->ReferenceIDObject) ? $this->objArticlebook->ReferenceIDObject->__toString() : null;

			if ($this->txtAuthor) $this->txtAuthor->Text = $this->objArticlebook->Author;
			if ($this->lblAuthor) $this->lblAuthor->Text = $this->objArticlebook->Author;

			if ($this->txtEdition) $this->txtEdition->Text = $this->objArticlebook->Edition;
			if ($this->lblEdition) $this->lblEdition->Text = $this->objArticlebook->Edition;

			if ($this->txtNumberOfPages) $this->txtNumberOfPages->Text = $this->objArticlebook->NumberOfPages;
			if ($this->lblNumberOfPages) $this->lblNumberOfPages->Text = $this->objArticlebook->NumberOfPages;

			if ($this->calPublicationDate) $this->calPublicationDate->DateTime = $this->objArticlebook->PublicationDate;
			if ($this->lblPublicationDate) $this->lblPublicationDate->Text = sprintf($this->objArticlebook->PublicationDate) ? $this->objArticlebook->__toString($this->strPublicationDateDateTimeFormat) : null;

			if ($this->txtPublisher) $this->txtPublisher->Text = $this->objArticlebook->Publisher;
			if ($this->lblPublisher) $this->lblPublisher->Text = $this->objArticlebook->Publisher;

			if ($this->txtIsbn) $this->txtIsbn->Text = $this->objArticlebook->Isbn;
			if ($this->lblIsbn) $this->lblIsbn->Text = $this->objArticlebook->Isbn;

		}



		///////////////////////////////////////////////
		// PROTECTED UPDATE METHODS for ManyToManyReferences (if any)
		///////////////////////////////////////////////





		///////////////////////////////////////////////
		// PUBLIC ARTICLEBOOK OBJECT MANIPULATORS
		///////////////////////////////////////////////

		/**
		 * This will save this object's Articlebook instance,
		 * updating only the fields which have had a control created for it.
		 */
		public function SaveArticlebook() {
			try {
				// Update any fields for controls that have been created
				if ($this->lstReferenceIDObject) $this->objArticlebook->ReferenceID = $this->lstReferenceIDObject->SelectedValue;
				if ($this->txtAuthor) $this->objArticlebook->Author = $this->txtAuthor->Text;
				if ($this->txtEdition) $this->objArticlebook->Edition = $this->txtEdition->Text;
				if ($this->txtNumberOfPages) $this->objArticlebook->NumberOfPages = $this->txtNumberOfPages->Text;
				if ($this->calPublicationDate) $this->objArticlebook->PublicationDate = $this->calPublicationDate->DateTime;
				if ($this->txtPublisher) $this->objArticlebook->Publisher = $this->txtPublisher->Text;
				if ($this->txtIsbn) $this->objArticlebook->Isbn = $this->txtIsbn->Text;

				// Update any UniqueReverseReferences (if any) for controls that have been created for it

				// Save the Articlebook object
				$this->objArticlebook->Save();

				// Finally, update any ManyToManyReferences (if any)
			} catch (QCallerException $objExc) {
				$objExc->IncrementOffset();
				throw $objExc;
			}
		}

		/**
		 * This will DELETE this object's Articlebook instance from the database.
		 * It will also unassociate itself from any ManyToManyReferences.
		 */
		public function DeleteArticlebook() {
			$this->objArticlebook->Delete();
		}		



		///////////////////////////////////////////////
		// PUBLIC GETTERS and SETTERS
		///////////////////////////////////////////////

		/**
		 * Override method to perform a property "Get"
		 * This will get the value of $strName
		 *
		 * @param string $strName Name of the property to get
		 * @return mixed
		 */
		public function __get($strName) {
			switch ($strName) {
				// General MetaControlVariables
				case 'Articlebook': return $this->objArticlebook;
				case 'TitleVerb': return $this->strTitleVerb;
				case 'EditMode': return $this->blnEditMode;

				// Controls that point to Articlebook fields -- will be created dynamically if not yet created
				case 'IdControl':
					if (!$this->lblId) return $this->lblId_Create();
					return $this->lblId;
				case 'IdLabel':
					if (!$this->lblId) return $this->lblId_Create();
					return $this->lblId;
				case 'ReferenceIDControl':
					if (!$this->lstReferenceIDObject) return $this->lstReferenceIDObject_Create();
					return $this->lstReferenceIDObject;
				case 'ReferenceIDLabel':
					if (!$this->lblReferenceID) return $this->lblReferenceID_Create();
					return $this->lblReferenceID;
				case 'AuthorControl':
					if (!$this->txtAuthor) return $this->txtAuthor_Create();
					return $this->txtAuthor;
				case 'AuthorLabel':
					if (!$this->lblAuthor) return $this->lblAuthor_Create();
					return $this->lblAuthor;
				case 'EditionControl':
					if (!$this->txtEdition) return $this->txtEdition_Create();
					return $this->txtEdition;
				case 'EditionLabel':
					if (!$this->lblEdition) return $this->lblEdition_Create();
					return $this->lblEdition;
				case 'NumberOfPagesControl':
					if (!$this->txtNumberOfPages) return $this->txtNumberOfPages_Create();
					return $this->txtNumberOfPages;
				case 'NumberOfPagesLabel':
					if (!$this->lblNumberOfPages) return $this->lblNumberOfPages_Create();
					return $this->lblNumberOfPages;
				case 'PublicationDateControl':
					if (!$this->calPublicationDate) return $this->calPublicationDate_Create();
					return $this->calPublicationDate;
				case 'PublicationDateLabel':
					if (!$this->lblPublicationDate) return $this->lblPublicationDate_Create();
					return $this->lblPublicationDate;
				case 'PublisherControl':
					if (!$this->txtPublisher) return $this->txtPublisher_Create();
					return $this->txtPublisher;
				case 'PublisherLabel':
					if (!$this->lblPublisher) return $this->lblPublisher_Create();
					return $this->lblPublisher;
				case 'IsbnControl':
					if (!$this->txtIsbn) return $this->txtIsbn_Create();
					return $this->txtIsbn;
				case 'IsbnLabel':
					if (!$this->lblIsbn) return $this->lblIsbn_Create();
					return $this->lblIsbn;
				default:
					try {
						return parent::__get($strName);
					} catch (QCallerException $objExc) {
						$objExc->IncrementOffset();
						throw $objExc;
					}
			}
		}

		/**
		 * Override method to perform a property "Set"
		 * This will set the property $strName to be $mixValue
		 *
		 * @param string $strName Name of the property to set
		 * @param string $mixValue New value of the property
		 * @return mixed
		 */
		public function __set($strName, $mixValue) {
			try {
				switch ($strName) {
					// Controls that point to Articlebook fields
					case 'IdControl':
						return ($this->lblId = QType::Cast($mixValue, 'QControl'));
					case 'ReferenceIDControl':
						return ($this->lstReferenceIDObject = QType::Cast($mixValue, 'QControl'));
					case 'AuthorControl':
						return ($this->txtAuthor = QType::Cast($mixValue, 'QControl'));
					case 'EditionControl':
						return ($this->txtEdition = QType::Cast($mixValue, 'QControl'));
					case 'NumberOfPagesControl':
						return ($this->txtNumberOfPages = QType::Cast($mixValue, 'QControl'));
					case 'PublicationDateControl':
						return ($this->calPublicationDate = QType::Cast($mixValue, 'QControl'));
					case 'PublisherControl':
						return ($this->txtPublisher = QType::Cast($mixValue, 'QControl'));
					case 'IsbnControl':
						return ($this->txtIsbn = QType::Cast($mixValue, 'QControl'));
					default:
						return parent::__set($strName, $mixValue);
				}
			} catch (QCallerException $objExc) {
				$objExc->IncrementOffset();
				throw $objExc;
			}
		}
	}
?>